home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / recent / create.lha / CreateIndex.isrx < prev    next >
Text File  |  1998-06-01  |  6KB  |  216 lines

  1. /* ImageStudio ARexx script **************************************/
  2. /* V1.0 2 Nov 97 by James Perrin */
  3. /* V2.0 19 Nov 97 added ability to update an index if new images
  4.    have been added to the directory */
  5. /* V2.1 24 May 98 added skipping of files unable to load eg pr0gressive jpegs */
  6.  
  7. /* Allow commands to return results */
  8.  
  9. options results
  10.  
  11. /* On error, goto ERROR:. Comment out this line if you wish to */
  12. /* perform your own error checking. */
  13.  
  14. signal on error
  15.  
  16. /* BEGIN PROGRAM *************************************************/
  17.  
  18. /* PROGRAM CONSTANTS - change these values to suit */
  19.  
  20. HTMLFile='Index.html'        /* What to call the html file, Oh Yes */
  21. SquareSize=100                    /* Size of square into which to fit pic */
  22. TNFormat='PNG'                    /* Thumbnail file format */
  23. TNExten='png'                        /* Thumnail file extension */
  24. TNPrefix='TN'                                    /* Thumbnail prefix */
  25. TableColumns=5                    /* No. of pics per row */
  26. TableBorder=1                        /* Size of table borders, in pixels */
  27.  
  28. FilePattern='~('HTMLFile'|'TNPrefix'#?)' /* only change if you understand arexx */
  29.  
  30. /* set program variables */
  31. nofile=0    /* flag that image can't be loaded */
  32.  
  33. /* get them files */
  34.  
  35. REQUEST_MULTIFILE TITLE '"Choose source files..."' PATTERN FilePattern STEM srcfiles.
  36.  
  37. /* Open html file and write basic info */
  38.  
  39. FILE_SPLIT FILE '"'srcfiles.files.0'"' STEM getpath.
  40. FILE_JOIN PATHPART '"'getpath.pathpart'"' FILEPART HTMLFile VAR WriteFile
  41.  
  42. if open('OutFile',WriteFile,'w') then
  43. do
  44.     call writeln('OutFile', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">')
  45.     call writeln('OutFile', '<HTML>')
  46.     call writeln('OutFile', '<HEAD>')
  47.     call writeln('OutFile', '<TITLE>Index of Directory '||getpath.pathpart||'</TITLE>')
  48.   call writeln('OutFile', '</HEAD>')
  49.     call writeln('OutFile', '<BODY>')
  50.     call writeln('OutFile', '<TABLE WIDTH="100%" BORDER='TableBorder'>')
  51.  
  52.     ColumnCount=1
  53.  
  54.     /* Process  each file */
  55.     do l = 0 to (srcfiles.files.count - 1)
  56.  
  57.         /* Create the destination file name */
  58.         FILE_SPLIT FILE '"'srcfiles.files.l'"' STEM filesplit.
  59.  
  60.         filename=left(filesplit.filepart,index(filesplit.filepart,'.')-1)
  61.  
  62.         FILE_JOIN PATHPART '"'filesplit.pathpart'"',
  63.         FILEPART '"'TNPrefix||filename'.'TNExten'"' VAR 'destfile'
  64.  
  65.  
  66.         /* if thumb nail not yet generated make one */
  67.         if exists(destfile) ~=1 then
  68.         do
  69.             /* Open the file, do our own error check */
  70.             signal off error
  71.                  
  72.             OPEN FILE '"'srcfiles.files.l'"' FORCE
  73.         
  74.             if (rc~=0) then
  75.             do
  76.                 /* deal with error */
  77.                 nofile=1
  78.                 signal on error
  79.                     
  80.             end    
  81.             else
  82.             do
  83.                 signal on error
  84.  
  85.                 /* Get and set size and depth info */
  86.                 IMAGEINFO_GET STEM ImageInfo.
  87.                 XPSize = SquareSize / ImageInfo.width
  88.                 YPSize = SquareSize / ImageInfo.height
  89.                 ImageDepth = ImageInfo.depth
  90.  
  91.                 /* 8-bit colors max */
  92.                 if ImageDepth>8 then
  93.                     ImageDepth=8
  94.  
  95.                 NumCol=1
  96.  
  97.                 do n=1 to ImageDepth
  98.                     NumCol=NumCol*2
  99.                 end
  100.  
  101.                 /* Fit image into square SquareSize X SquareSize */
  102.                 if (XPSize < YPSize) then
  103.                     PSize = (XPSize * 100) + 0.5
  104.                 else
  105.                     PSize = (YPSize * 100) + 0.5
  106.  
  107.                 PSize=trunc(PSize,0) /* number must be integer */
  108.     
  109.                 /* Rescale image , colour convertion neccessary for colour averaging */
  110.                 COLOURS SIXTEENMILLION
  111.                 SCALE  PSize PSize PERCENT METHOD "AVERAGE"
  112.                 COLOURS NUMCOLOURS NumCol
  113.  
  114.                 /* Save file */
  115.                 SAVE FILE '"'destfile'"' FORMAT "PNG" ARGS '"INTERLACE=ADAM7"'   
  116.             end
  117.  
  118.         end    /* if destfile */
  119.  
  120.         /* Write HTML for ThumbNail */
  121.         if ColumnCount=1 then
  122.             call writeln('OutFile','<TR>')
  123.  
  124.         if(~nofile) then /* TN exists */
  125.             call writeln('OutFile','<TD><A HREF="'filesplit.filepart'">'||,
  126. '<IMG SRC="'TNPrefix||filename'.'TNExten'" ALT="'filesplit.filepart'"></A>')
  127.         else    /* unable to create TN */
  128.         do
  129.             call writeln('OutFile','<TD><A HREF="'filesplit.filepart'">'||,
  130. filesplit.filepart'"</A>')
  131.             nofile=0
  132.         end
  133.             
  134.         ColumnCount=ColumnCount+1
  135.  
  136.         if ColumnCount > 5 then
  137.         do
  138.             call writeln('OutFile','</TR>')
  139.             ColumnCount=1
  140.         end
  141.  
  142.     end /* file loop */
  143.  
  144.     /* Finish writing html and close file */
  145.     if ColumnCount>1 then
  146.         call writeln('OutFile','</TR>')
  147.  
  148.     call writeln('OutFile', '</TABLE>')
  149.     call writeln('OutFile', '</BODY>')
  150.     call writeln('OutFile', '</HTML>')
  151.     call close('OutFile')
  152.  
  153. end /* if outfile */
  154.  
  155. /* END PROGRAM ***************************************************/
  156.  
  157. exit
  158.  
  159. /* On ERROR */
  160.  
  161. ERROR:
  162.  
  163. /* If we get here, either an error occurred with the command's */
  164. /* execution or there was an error with the command itself. */
  165. /* In the former case, rc2 contains the error message and in */
  166. /* the latter, rc2 contains an error number. SIGL contains */
  167. /* the line number of the command which caused the jump */
  168. /* to ERROR: */
  169.  
  170. if datatype(rc2,'NUMERIC') == 1 then do
  171.    /* See if we can describe the error with a string */
  172.  
  173.    select
  174.       when rc2 == 103 then
  175.          err_string = "ERROR 103, "||,
  176.             "out of memory at line "||SIGL
  177.       when rc2 == 114 then
  178.          err_string = "ERROR 114, "||,
  179.             "bad command template at line "||SIGL
  180.       when rc2 == 115 then
  181.          err_string = "ERROR 115, "||,
  182.             "bad number for /N argument at line "||SIGL
  183.       when rc2 == 116 then
  184.          err_string = "ERROR 116, "||,
  185.             "required argument missing at line "||SIGL
  186.       when rc2 == 117 then
  187.          err_string = "ERROR 117, "||,
  188.             "value after keywork missing at line "||SIGL
  189.       when rc2 == 118 then
  190.          err_string = "ERROR 118, "||,
  191.             "wrong number of arguments at line "||SIGL
  192.       when rc2 == 119 then
  193.          err_string = "ERROR 119, "||,
  194.             "unmatched quotes at line "||SIGL
  195.       when rc2 == 120 then
  196.          err_string = "ERROR 120, "||,
  197.             "line too long at line "||SIGL
  198.       when rc2 == 236 then
  199.          err_string = "ERROR 236, "||,
  200.             "unknown command at line "||SIGL
  201.       otherwise
  202.          err_string = "ERROR "||rc2||", at line "||SIGL
  203.       end
  204.         end
  205. else if rc2 == 'RC2' then do
  206.    err_string = "ERROR in command at line "||SIGL
  207.    end
  208. else do
  209.         err_string = rc2||", line "||SIGL
  210.         end
  211.  
  212. request_message TEXT '"'err_string'"'
  213.  
  214. exit
  215.  
  216.